<template>
    <div class="search-div">
        <!-- 添加按钮 -->
        <div class="tools-div">
            <el-button type="success" size="small" @click="addModelRef.show()">添 加</el-button>
        </div>
        <!--- 角色表格数据 -->
        <!---懒加载的树形表格-->
        <el-table :data="list" style="width: 100%" row-key="id" border>
            <el-table-column prop="name" label="品牌名" />
            <el-table-column prop="logo" label="logo" #default="scope">
                <img :src="scope.row.logo" width="50" />
            </el-table-column>

            <el-table-column prop="createTime" label="创建时间" />
            <el-table-column prop="updateTime" label="更新时间" />
            <el-table-column label="操作">
                <template #default="scope">
                    <el-button type="primary" size="small" @click="editModelRef.show(scope.row)">编辑</el-button>
                    <el-button type="danger" size="small" @click="handleDelete(scope.row.id)">删除</el-button>
                </template>
            </el-table-column>

        </el-table>


        <!--分页条-->
        <el-pagination v-model:current-page="pageParams.pageNum" v-model:page-size="pageParams.pageSize"
            :page-sizes="[10, 20, 50, 100]" @size-change="fetchData" @current-change="fetchData"
            layout="total, sizes, prev, pager, next" :total="total" />

    </div>
    <add-model ref="addModelRef" @refresh="fetchData" />
    <edit-model ref="editModelRef" @refresh="fetchData" />

</template>

<script setup>
import { ref } from 'vue';

import addModel from './components/add-model.vue';
import editModel from './components/edit-model.vue';

// import { findAllNodesApi, exportCategoryDataApi, removeCategoryApi } from '@/api/category'
import { getBrandPageListApi, removeBrandApi } from '@/api/brand'
const addModelRef = ref()
const queryDto = ref({
    name: ""
})
const editModelRef = ref()
const importDataRef = ref()

// 分页条总记录数
let total = ref(0)
const pageParams = ref({
    pageNum: 1,
    pageSize: 10,

})
// 定义表格数据模型
let list = ref([])

// 远程调用后端分页查询接口
const fetchData = async () => {

    const { data } = await getBrandPageListApi({
        ...queryDto.value,
        ...pageParams.value
    });
    list.value = data.list || []
    total.value = data.total || 0

}


const handleDelete = (id) => {
    ElMessageBox.confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then(() => {
        // 确定
        removeBrandApi(id).then(() => {
            ElMessage({
                type: 'success',
                message: '删除成功!'
            })
            fetchData()
        })
    })
}

fetchData()

</script>

<style scoped>
.search-div {
    margin-bottom: 10px;
    padding: 10px;
    border: 1px solid #ebeef5;
    border-radius: 3px;
    background-color: #fff;
}

.tools-div {
    margin: 10px 0;
    padding: 10px;
    border: 1px solid #ebeef5;
    border-radius: 3px;
    background-color: #fff;
}
</style>